package cn.mw.cmdb.virtualization.utils;

import cn.mw.microMonitorCommon.util.ListMapObjUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author gengjb
 * @description 虚拟化数据过滤
 * @date 2024/11/22 15:44
 */
public class VirtualizationDataFilterUtil {

    public static List dataFilter(List data,String queryKey,Object queryValue){
        if(CollectionUtils.isEmpty(data) || StringUtils.isEmpty(queryKey) || queryValue == null){
            return data;
        }
        List<Map<String,Object>> realDatas = ListMapObjUtils.objectsToMaps(data);
        if(CollectionUtils.isEmpty(realDatas)){
            return realDatas;
        }
        return realDatas.stream().filter(item->item.get(queryKey) != null && item.get(queryKey).toString().contains(queryValue.toString())).collect(Collectors.toList());
    }
}
